package com.hongyun.tms.web.controller;

import com.hongyun.tms.common.IdDto;
import com.hongyun.tms.common.PageResponseDto;
import com.hongyun.tms.common.dto.crewcert.CrewCertQueryDto;
import com.hongyun.tms.common.dto.crewcert.CrewCertSaveReqDto;
import com.hongyun.tms.common.vo.CrewCertVO;
import com.hongyun.tms.domain.AjaxResult;
import com.hongyun.tms.service.ICrewCertService;
import com.hongyun.tms.service.ISysFileBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 船员证书档案
 *
 * @author lipeng
 * @date 2024-05-31
 */
@RestController
@RequestMapping("seaman/cert")
@Api(value = "船员证书", tags = "船员证书")
public class CrewCertController {
    @Resource
    private ICrewCertService crewCertService;

    @Resource
    private ISysFileBusinessService fileBusinessService;

    /**
     * 分页查询船员证照
     */
    @GetMapping("list")
    @ApiOperation(value = "分页查询船员证照", notes = "分页")
    public AjaxResult<PageResponseDto<CrewCertVO>> page(CrewCertQueryDto dto) {
        PageResponseDto<CrewCertVO> pageList = crewCertService.pageList(dto);
        return AjaxResult.success(pageList);
    }

    /**
     * 单个查询
     */
    @GetMapping("getById")
    @ApiOperation(value = "单个查询", notes = "单个查询")
    public AjaxResult<CrewCertVO> getById(@RequestParam("id") Long id) {
        return AjaxResult.success(crewCertService.getOneById(id));
    }
    /**
     * 删除证书
     */
    @PostMapping("remove")
    @ApiOperation(value = "删除证书", notes = "删除证书")
    public AjaxResult removeCertById(@RequestBody @Valid IdDto dto) {
        crewCertService.removeById(dto.getId());
        return AjaxResult.success();
    }


    @PostMapping("save")
    @ApiOperation(value = "修改或新增证书", notes = "修改或新增证书")
    public AjaxResult saveCert(@RequestBody @Valid CrewCertSaveReqDto dto) {
        crewCertService.insertOrUpdate(dto);
        return AjaxResult.success();
    }
}
